﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ContourBuilder.GUI;
using ITAP.ContourBuilder.Components;
using ITAP.Core.Modelling;


namespace ITAP.ContourBuilder.Operations
{
    public class OperationMoveConnectorsWithOffset : OperationWithSelectedConnectors
    {
        public override string ToString()
        {
            return "Сместить соединители";
        }

        public override void Execute()
        {
            base.Execute();

            FormMoveConnectorsWithOffset form = new FormMoveConnectorsWithOffset();
            if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                this.Cancel();
                return;
            }

            ModelVector vector = null;
            switch(form.OffsetType)
            {
                case ConnectorOffsetType.Left:
                    vector = new ModelVector(-form.OffsetValue, 0);
                    break;
                case ConnectorOffsetType.Right:
                    vector = new ModelVector(form.OffsetValue, 0);
                    break;
                case ConnectorOffsetType.Down:
                    vector = new ModelVector(0, -form.OffsetValue);
                    break;
                case ConnectorOffsetType.Up:
                    vector = new ModelVector(0, form.OffsetValue);
                    break;
            }

            foreach (ContourConnector connector in this.connectors)
                connector.MoveWithOffset(vector);
            this.Control.UpdateModel();
            this.Exit();
        }
    }
}
